package wechat

import (
	"github.com/medivhzhan/weapp/v3"
)

type openIdResolver struct {
	AppId  string
	Secret string
}

func NewOpenIdResolver(appId, secret string) *openIdResolver {
	return &openIdResolver{
		AppId:  appId,
		Secret: secret,
	}
}

func (s *openIdResolver) Resolve(code string) (string, error) {
	_, err := weapp.NewClient(s.AppId, s.Secret).Login(code)
	if err != nil {
		return "error token", nil
	}
	return code, nil
}
